#-*- coding:utf-8 -*-
"""
@Time:2020/9/1614:19
@Auth:DaiXvWen
@File:__init__.py.py
********************项目的初始化文件***********************
"""
#项目的初始化文件
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_wtf import CSRFProtect


csrf=CSRFProtect()  #实例化csrf
db = SQLAlchemy()  #实例化db
migrate=Migrate()  #实例化migrate

def createApp(config):
    #实例化app
    app=Flask(__name__)
    app.config.from_object(config)
    from FlaskPro.OA.views import oa  #从视图中导入视图引用过的oa
    app.register_blueprint(oa)  #注册oa蓝图

    migrate.init_app(app,db)  #migrate关联app与db
    db.init_app(app) ##db关联app
    csrf.init_app(app)  ##csrf关联app


    #编写过滤器，让前端密码显示*****
    def setpwd(pwd):
        return "******"
    #添加到过滤器中
    app.add_template_filter(setpwd,"setpwd")

    # attendance_me--自定义过滤器，中文显示假条状态
    def jiatiao(jt):
        if jt==0:
            return "申请中"
        if jt==1:
            return "已通过"
        if jt==2:
            return "已驳回"

    # attendance_me--自定义过滤器，中文显示请假类型
    app.add_template_filter(jiatiao, "jiatiao")
    def qingjia(qj):
        if qj == 1:
            return "事假"
        if qj == 2:
            return "婚嫁"
        if qj == 3:
            return "产假"
        if qj == 4:
            return "病假"
        if qj == 5:
            return "年假"
        if qj == 6:
            return "调休"

    app.add_template_filter(qingjia, "qingjia")

    return app #return 出app
